package com.qlm.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson.JSONObject;
import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.qlm.interceptor.AdminOperateInterceptor;
import com.qlm.interceptor.AuthInterceptor;
import com.qlm.service.IScoreService;
import com.qlm.service.impl.ScoreServiceImpl;
import com.qlm.view.ResultMessage;

/**
 * 积分配置管理
 * @author raoy
 *
 */
@Before({AuthInterceptor.class , AdminOperateInterceptor.class})
public class ScoreManageController extends Controller {
	
	protected final static Logger logger = LoggerFactory.getLogger(ScoreManageController.class); 	
	private IScoreService scoreService = enhance(ScoreServiceImpl.class);
	
	/**
	 * 跳转积分配置页面
	 */
	public void scoreInfoSkip(){		
		//获取积分设置信息
		ResultMessage resultMessage = scoreService.getScoreConfig();
		logger.info("method:scoreInfoSkip return:resultMessage("+resultMessage+")");
		setAttr("msg", resultMessage);
		render("/page/scoreInit.jsp");
	}
	
	/**
	 * 积分配置处理
	 */
	public void scoreUpd(){
		//获取积分设置信息
		Integer score_start = getParaToInt("score_start");
		Integer score_end = getParaToInt("score_end");
		Integer default_score = getParaToInt("default_score");
		Integer add_score = getParaToInt("add_score");
		Integer attention_score = getParaToInt("attention_score");
		Integer share_score = getParaToInt("share_score");
		Integer days = getParaToInt("days");
		if(score_start > score_end){
			renderJson(JSONObject.toJSONString(ResultMessage.setAllMessage(1, "起始积分不能大于结束积分")));
			return;
		}
		Integer id = getParaToInt("id");
		logger.info("method:scoreUpd param:score_start("+score_start+"),score_end("+score_end+")");		
		//保存积分设置信息
		ResultMessage resultMessage = scoreService.saveScoreConfig(score_start,score_end,id,default_score, add_score, days,attention_score,share_score);	
		logger.info("method:scoreUpd return:resultMessage("+resultMessage+")");		
		renderJson(JSONObject.toJSONString(resultMessage));
	}
}
